package org.csu.mypetstore.web.servlets;

import org.csu.mypetstore.service.CatalogService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class SearchProductAjaxServlet extends HttpServlet {
    private CatalogService catalogService = new CatalogService();
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        name = new String(name.getBytes("iso-8859-1"),"utf-8");
        String result = catalogService.searchProduct(name);
        response.getWriter().write(result);
    }
}

